package com.tianhao.luo.nouse;

/**
 * @author tianhao.luo
 * @date 2019/12/23 11:19
 */
public class TemplateMethodTest {
    public static void main(String[] args) {
        SubClass subClass = new SubClass();
        subClass.operation();
        SubClass2 subClass2 = new SubClass2();
        subClass2.operation();
    }
}

abstract class AbstractClass{
    public void operation() {
        // 模拟数据库连接
        // open
        System.out.println("pre ...");

        System.out.println("step 1..");

        System.out.println("step 2 ..");

        templateMethod();
        // ....
    }

    abstract protected void templateMethod();
}

class SubClass extends AbstractClass {

    @Override
    protected void templateMethod() {
        System.out.println("具体实现方法的步骤1");
    }
}

class SubClass2 extends AbstractClass {

    @Override
    protected void templateMethod() {
        System.out.println("具体实现方法的步骤2");
    }
}